<?php

namespace app\api\controller;

use app\index\model\Question;
use think\Controller;
use think\facade\Session;
use think\Request;

class Api extends Controller
{
    //添加题库
    public function add(){
        if($this->request->isPost()){
            $data = $this->request->param();
            $a = new \app\common\model\Api();
            $q = new Question();
            if($a->get_Token() != $data['token']){
                return '0';
            }
            //token正确
            if($q->add($data)){
                return '1';
            }
            return '0';
        }else{
            return '0';
        }
    }
    //查看答案
    public function ask(){
        if(Session::has('main_user')){
            if($this->request->isPost()){
                $id = $this->request->param('id/d');

                $q = new \app\common\model\Api();
                $answer = $q->get_ask($id);
                return json_ask(0,'成功',$answer);
            }
            return json_ask(0,'','请正确请求');
        }
        return json_ask(0,'','请先登陆账号才可以查看答案');
    }
}
